package com.ruoyi.infoManagement.service.Impl;

import com.ruoyi.infoManagement.mapper.RequestCasMapper;
import com.ruoyi.infoManagement.service.RequestCasService;
import com.ruoyi.infoManagement.utils.HttpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
//原来是用这个service类来处理跨不同后端请求数据的，通过本后端请求cas的后端
@Service
public class RequestCasServiceImpl implements RequestCasService {
  @Autowired
  private RequestCasMapper requestCasMapper;

  @Override
  public String getServiceByName(String name) {
    String id = requestCasMapper.getIdByName(name);
    if(id==null){
      return "failure";
    }
    System.out.println(id);
    HashMap<String, String> param = new HashMap<String, String>();
    param.put("id", id);
    String response = "";
    try {
      response = HttpUtil.setHttpRequest("https://127.0.0.1/cas/services/getServiceById", param, "POST");
      System.out.println(response);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return response;
  }
  public String getServiceByUrl(String url){
    String id = requestCasMapper.getIdByUrl(url);
    if(id==null){
      return "failure";
    }
    System.out.println(id);
    HashMap<String, String> param = new HashMap<String, String>();
    param.put("id", id);
    String response = "";
    try {
      response = HttpUtil.setHttpRequest("https://127.0.0.1/cas/services/getServiceById", param, "POST");
      System.out.println(response);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return response;
  }

}
